package com.yst.metho.web.application.projectversion.views;

import java.util.ArrayList;
import java.util.Collection;

import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.naming.NamingException;

import nextapp.echo2.app.Column;
import nextapp.echo2.app.Extent;
import nextapp.echo2.app.Grid;
import nextapp.echo2.app.Insets;
import nextapp.echo2.app.Label;

import com.yst.metho.web.application.components.DoubleListComponent;
import com.yst.metho.web.application.user.renderer.UserListRenderer;
import com.yst.metho.web.application.utils.Locator;
import com.yst.suivi.data.activities.Activity;
import com.yst.suivi.status.StatusConstants;

public class AffectActivityPane extends Column
{

	private String mId = null;

	private DoubleListComponent mUsers;

	public AffectActivityPane(Activity act, Collection usrs) throws FinderException, NamingException, CreateException
	{
		super();
		setCellSpacing(new Extent(10));
		setInsets(new Insets(10));
		Grid headerGrid = new Grid();
		headerGrid.setInsets(new Insets(0, 2));
		add(headerGrid);

		Label label;
		label = new Label("Nom");
		headerGrid.add(label);
		label = new Label(act.getNom());
		headerGrid.add(label);

		label = new Label("Duree");
		headerGrid.add(label);
		label = new Label(act.getDuree().toString());
		headerGrid.add(label);

		label = new Label("Classification");
		headerGrid.add(label);
		label = new Label(act.getFolder().getNom());
		headerGrid.add(label);

		label = new Label("Role");
		headerGrid.add(label);
		label = new Label(act.getTeamRole().getNom());
		headerGrid.add(label);

		label = new Label("Collaborateur");
		headerGrid.add(label);

		if (null != act)
		{
			mId = act.getId();
			mUsers = new DoubleListComponent(Locator.getActivityView().getAffectedUser(act), usrs, new UserListRenderer());
			headerGrid.add(mUsers);
			if (StatusConstants.CLOSE == act.getStatus())
			{
				mUsers.setEnabled(false);
			}
		}
		else
		{
			mUsers = new DoubleListComponent(new ArrayList(), usrs, new UserListRenderer());
			headerGrid.add(mUsers);
		}
	}

	/**
	 * @return the id
	 */
	public String getId()
	{
		return mId;
	}

	/**
	 * @return the users
	 */
	public Collection getUsers()
	{
		return mUsers.getSelectedList();
	}

}
